import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { ConfigService } from './config.service';
import { News } from '../model/news';

@Injectable()
export class NewsService {

  constructor(private http:HttpClient
    ,private config:ConfigService) { }


     private getNewsListUrl=this.config.host+"/manage/getNewsList";

     getNewsList(){

     return this.http.get(this.getNewsListUrl).toPromise();
  
     }
       
      private addNewsUrl=this.config.host+"/manage/updateNews";
      addNews(news:News){
        let p={

          "title": news.title,
          "content": news.content,
          "author": news.author,
           "px": news.px
        }
        return this.http.post(this.addNewsUrl,p).toPromise();

      }

      private deleteNewsUrl=this.config.host+"/manage/deleteNews";
      deleteNews(id:string){
        let p={
             "newsid":id
        }
        return this.http.post(this.deleteNewsUrl,p).toPromise();
      }
    }
